package cn.longge.listener;

import cn.longge.entity.SysArea;
import cn.longge.mapper.SysAreaMapper;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

public class SysAreaListener extends AnalysisEventListener<SysArea> {
    List<SysArea> areas = new ArrayList<SysArea>();

    private SysAreaMapper areaMapper;

    public SysAreaListener(SysAreaMapper areaMapper){
        this.areaMapper = areaMapper;
    }

    @Override
    public void invoke(SysArea area, AnalysisContext analysisContext) {
        areas.add(area);
        if(areas.size() == 10){
            areaMapper.insertMany(areas);
            areas.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        if(areas.size() > 0){
            areaMapper.insertMany(areas);
            areas.clear();
        }
    }
}
